package itsm.isperp.module.controller.app;

import itsm.isperp.framework.data.domain.PageResponse;
import itsm.isperp.framework.web.controller.BaseController;
import itsm.isperp.framework.web.request.JqGridFilterRuleOp;
import itsm.isperp.framework.web.request.JqGridRequest;
import itsm.isperp.module.entity.app.AppCalendarWorkdate;
import itsm.isperp.module.service.app.AppCalendarWorkdateService;

import javax.servlet.http.HttpServletRequest;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * 
 * 
 * @author lizx
 * @date 2013-5-12
 * @version V1.0
 */
@Controller
@RequestMapping("app/calendar/workdate")
public class AppCalendarWorkdateController extends
		BaseController<AppCalendarWorkdate> {

	@Autowired
	protected AppCalendarWorkdateService appCalendarWorkdateService;

	@Override
	public AppCalendarWorkdateService getService() {
		return appCalendarWorkdateService;
	}

	@Override
	public String getPageTitle() {
		return "工作日设置";
	}

	@RequestMapping("listByConfig")
	@ResponseBody
	public PageResponse<AppCalendarWorkdate> listByConfig(
			JqGridRequest request, HttpServletRequest req) {

		String configId = req.getParameter("configId");

		String dateType = req.getParameter("dateType");

		if (StringUtils.isEmpty(configId)) {
			return null;
		}

		request.isPageable(false).addFilterRule("app_calendar_config_id",
				JqGridFilterRuleOp.eq, configId);

		if (StringUtils.isEmpty(dateType)) {
			request.addFilterRule("date_type", JqGridFilterRuleOp.eq, dateType);
		}

		return this.getService().findAll(request).toPage();

	}

}
